#ifndef CHARACTER_H
#define CHARACTER_H

#include <sqlite3.h>
#include "Logger.h"
#include "Constants.h"

struct CharacterDesc {
	int dbId, CharacterTypeID, levelID, textureResolution, lifespan, width, height, textureWidth, textureHeight, ticksPerFrame, hookCharacterDbId;
	double x, y, hp, rotX, rotY, rotZ, xvel, yvel;
	string name, textureFile;
	bool invulnerable, isSolid, hasCollision, isPlayer, isAnimated;
	DWORD creationTime;
};

static int CharacterUIDCounter = 0;

class Character {
public:
	int texUID;
	
	Character(int CharacterID);
	Character(int CharacterTypeID, double xpos, double ypos, double velX, double velY, int lifespan);
	~Character();

	void InitializeCharacterId(int pos); // IMPORTANT: Call only once!

	Direction GetFacingToDirection();
	int GetDBId();
	int GetUId();
	double GetCX();
	double GetCY();

	double GetVX();
	double GetVY();

	double GetYaw();
	double GetPitch();
	double GetRoll();

	int GetHookCharacterDBId();
	string GetTextureFile();
	bool IsPlayerCharacter();
	bool IsAlive();

	void SetHookCharacterID(int pos);
	void SetVelocity(double xv, double yv);
	void SetVelocityX(double xv);
	void SetVelocityY(double yv);
	void SetInvulnerable(bool inv);
	void FillQuad(int width, int height);

	void Move();
	void MoveManually(double x, double y);
	void NextAnimationFrame();
	void UpdateAnimationDirection();

	VERTEX CharacterQuad[4];
private:

	enum AnimationDirection {
		Up,
		Down,
		Left,
		Right,
		NotMoving,
		NoAnimation
	};

	AnimationDirection animDirection;
	CharacterDesc CharacterData;
	Direction facingTo;

	AnimationDirection runningAnimationDirection;
	int animationStep;
	int totAnimSteps;
	int lastFrame;

	int uID;
	int hookCharacterId;


};

#endif